<?php 

	header("Content-type:image/jpeg");
		
		
	 $old=getimagesize('1.jpg');
/*	 Array
(
    [0] => 500
    [1] => 750
    [2] => 2
    [3] => width="500" height="750"
    [bits] => 8
    [channels] => 3
    [mime] => image/jpeg
)*/
	 $thumb_w=$old[0]/2;
	 $thumb_h=$old[1]/2;

	 switch ($old[2]) {
	 	case '1':
	 		$old_img=imagecreatefromgif('1.gif');
	 		break;
	 	case '2':

	 		$old_img=imagecreatefromjpeg('1.jpg');
	 		break;
	 	default:
	 		$old_img=imagecreatefrompng('1.png');
	 		break;
	 };

	 $thumb=imagecreatetruecolor($thumb_w,$thumb_h);

	  imagecopyresized( $thumb ,$old_img,0 ,0 ,0, 0,$thumb_w,$thumb_h,$old[0],$old[1]);

	  ob_clean();


	  switch ($old[2]) {
	  	case '1':
	  		imagegif($thumb,'thumb.gif');
	  		break;
	  	case '2':
	  		imagejpeg($thumb,'thumb.jpeg');
	  		break;	
	  	default:
	  		imagepng($thumb,'thumb.png');
	  		break;
	  };


	  // imagedestroy($thumb);

	 
?>
